/*
 * @Description  : 收藏
 * @Author       : zhao
 * @Date         : 2022-06-28 11:16:19
 * @LastEditors  : zhao
 * @LastEditTime : 2022-07-25 09:35:28
 */


import { Message } from "element-ui"
import { AddCollectRecord, GetBrowsingRecord, DeleteCollectRecordAll, DeleteCollectRecord, } from '@/api/CollectRecord'

const state = {

    isOpen: false, //

}

const mutations = {

}

const actions = {

    addCollectRecord({ dispatch, rootState, state }, data) {
        return new Promise((resolve, reject) => {
            AddCollectRecord(data).then(res => {
                if (res.code == 200) {
                    Message.success(res.msg || "添加成功")
                    resolve(res)
                } else {
                    Message.success(res.msg || "添加失败")

                }

            }).catch(err => {
                reject(err)
            })
        })

    },
    getBrowsingRecord({ dispatch, rootState, state }, data) {
        return new Promise((resolve, reject) => {
            GetBrowsingRecord(data).then(res => {
                if (res.code == 200) {

                    resolve(res)
                } else {
                    Message.success(res.msg || "获取收藏夹失败")

                }

            }).catch(err => {
                reject(err)
            })
        })

    },
    deleteCollectRecordAll({ dispatch, rootState, state }, data) {
        return new Promise((resolve, reject) => {
            DeleteCollectRecordAll(data).then(res => {
                if (res.code == 200) {
                    Message.success(res.msg || "删除成功")
                    resolve(res)
                } else {
                    // Message.success(res.msg || "删除失败")

                }

            }).catch(err => {
                reject(err)
            })
        })

    },
    deleteCollectRecord({ dispatch, rootState, state }, data) {
        return new Promise((resolve, reject) => {
            DeleteCollectRecord(data).then(res => {
                if (res.code == 200) {
                    Message.success(res.msg || "删除成功")
                    resolve(res)
                } else {
                    // Message.success(res.msg || "删除失败")

                }

            }).catch(err => {
                reject(err)
            })
        })

    },
}
const getters = {

}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}